#coding:utf-8

import scrapy

from proxy.items import ProxyItem

class ProxySpider(scrapy.Spider):
	name = 'chnlanker'
	allowed_domains = ['chnlanker.com']
	
	start_urls = [
		"http://proxy.chnlanker.com/?t=fast",
		"http://proxy.chnlanker.com/?t=transparent",
		"http://proxy.chnlanker.com/?t=hightanonymous",
		"http://proxy.chnlanker.com/?t=anonymous"
	]

	def parse(self, response):
		contents = response.xpath("//table/tr/td/text()").extract()
		for i in range(len(contents)/5-1):
			item = ProxyItem()
			item['ip'] = contents[(i+1)*5+1]
			item['port'] = contents[(i+1)*5+2]
			item['loc'] = contents[(i+1)*5+4]
			item['ptype'] = contents[(i+1)*5+3]
			item['time'] = "null"
			yield item
